package com.hzb.springcloud.controlller;

import com.hzb.springcloud.entities.CommonResult;
import com.hzb.springcloud.entities.Payment;
import com.hzb.springcloud.service.IPaymentService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version v1.0
 * @ProjectName: cloud2020
 * @ClassName: PaymentController
 * @Description: TODO(一句话描述该类的功能)
 * @Author: huangZB
 * @Date: 2020/3/16 14:10
 */
@RestController
public class PaymentController {

        @Resource
        private IPaymentService paymentService;

        @Value("${server.port}")
        private String serverPort;


        /**
         * @Title:
         * @Description: TODO(这里用一句话描述这个方法的作用)
         * @param @param
         * @return @return
         * @author huangZB
         * @throws
         * @date
         */
        @RequestMapping(value = "/payment/creat")
        public CommonResult<Payment> create(@RequestBody Payment payment){
            int i = paymentService.create(payment);
            if (i >0) {
                return new CommonResult(200, "插入成功", i);
            }else {
                return new CommonResult(500, "插入失败", null);
            }
        }

        /**
         * @Title:
         * @Description: TODO(这里用一句话描述这个方法的作用)
         * @param @param
         * @return @return
         * @author huangZB
         * @throws
         * @date
         */
        @GetMapping(value = "/payment/getPaymentById/{id}")
        public CommonResult getPaymentById(@PathVariable("id") String  id){
            Payment payment = paymentService.getPaymentById(id);
            if (payment != null) {
                return new CommonResult(200, "查询成功", payment);
            }else {
                return new CommonResult(500, "查询失败", null);
            }
        }

        /**
         * @Title:
         * @Description: TODO(这里用一句话描述这个方法的作用)
         * @param @param
         * @return @return
         * @author huangZB
         * @throws
         * @date
         */
        @GetMapping(value = "/payment/lb")
        public String lb(){

            return serverPort;
        }
    }
